package com.eip.zd.controller;

import com.eip.zd.common.Result;
import com.eip.zd.entity.Cust;
import com.eip.zd.service.CustService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/cust")
public class CustController {
    @Resource
    CustService custService;
    @GetMapping("/getTenCust")
    public Result getTenCust(@RequestParam(required = false) String keyword) {
        List<Cust> custList = custService.getTenCust(keyword);
        return Result.success(custList);
    }
    @GetMapping("/getCustList")
    public Result getCustList(@RequestParam(required = false) String keyword) {
        List<Cust> custList = custService.getCustList(keyword);
        return Result.success(custList);
    }
    @GetMapping("/getCustByCustId/{custId}")
    public Result getCustByCustId(@PathVariable String custId){
        Cust cust = custService.getCustByCustId(custId);
        return Result.success(cust);
    }
    @PostMapping("/add")
    public Result addCust(@RequestBody Cust cust) {
        custService.add(cust);
        return Result.success();
    }
    @PostMapping("/update")
    public Result updateCust(@RequestBody Cust cust) {
        custService.update(cust);
        return Result.success();
    }
    @PostMapping("/remove/{id}")
    public Result removeCust(@PathVariable Long id) {
        custService.remove(id);
        return Result.success();
    }
    @PostMapping("/ifUse/{id}")
    public Result ifUse(@PathVariable Long id) {
        custService.ifUse(id);
        return Result.success();
    }
}
